<?php
class CourseModel extends CI_Model{
    
    public function getCourseByUser ($userId) {
        /*
        SELECT groups.groupId, courses.courseId, courses.name
        FROM user_group, groups, courses
        WHERE user_group.userId = 4
        AND user_group.groupId = groups.groupId
        AND groups.courseId = courses.courseId
        GROUP BY courses.name
        ORDER BY courses.name
        */
        
        $this->db->select ('groups.groupId, courses.courseId, courses.name');
        $this->db->from ('user_group, groups, courses');
        $this->db->where('user_group.userId',$userId);
        $this->db->where('user_group.groupId = groups.groupId'); 
        $this->db->where('groups.courseId = courses.courseId'); 
        $this->db->group_by('courses.name');
        $this->db->order_by('courses.name');
        $query = $this->db->get();
        $foundCourses = $query->result();
        return $foundCourses;
    }
    
    
    
}
